package com.ww.springboot.common;
import lombok.Data;
import com.ww.springboot.common.ResultCode;
// https://www.cnblogs.com/pengb/p/17915982.html
@Data
public class Response<T> {
    private int code;
    private String description;
    private T result;
    private String expandMsg;

    public Response(int code, String description, T data) {
        this.code = code;
        this.description = description;
        this.result = data;
    }

    public static <T> Response<T> success(String description) {
        return new Response<T>(ResultCode.SUCCESS.getCode(), description, null);
    }

    public static <T> Response<T> success(T data) {
        return new Response<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    public static <T> Response<T> success(T data, String description) {
        return new Response<T>(ResultCode.SUCCESS.getCode(), description, data);
    }

    public static <T> Response<T> forbidden(T data) {
        return new Response<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
    }

    public static <T> Response<T> error(T data) {
        return new Response<T>(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), data);
    }

    public static <T> Response<T> error(String description) {
        return new Response<T>(ResultCode.FAILED.getCode(), description, null);
    }

    public static <T> Response<T> error(String description, T data) {
        return new Response<T>(ResultCode.FAILED.getCode(), description, data);
    }
}

